/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package optimizacion.distribuciones;

import com.sun.org.apache.xerces.internal.impl.xpath.regex.Match;
import java.util.Random;

/**
 *
 * @author ricardo
 */
public class Normal {

    private double varianza;
    private double media;
    private final MersenneTwisterFast gen;

    public Normal(double varianza, double media) {
        this.varianza = varianza;
        this.media = media;
        this.gen=new MersenneTwisterFast();
    }

   

    public double generar() {
        double u1 = gen.nextDouble();
        double u2 = gen.nextDouble();
        double r = Math.sqrt(-2 * Math.log(u1));
        double theta = 2 * Math.PI * u2;
        double z1 = r * Math.cos(theta);
        return (media + z1 * Math.sqrt(varianza));
    }

    public void setMedia(double media) {
        this.media = media;
    }

    public void setVarianza(double varianza) {
        this.varianza = varianza;
    }
}
